﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace DieuTriNoiTru
{
    class clsKetnoi
    {
        public static SqlConnection conn = new SqlConnection();

        public static void connect()
        {
            conn = new SqlConnection(@"Data Source=iloveit-pc\sqlexpress;Initial Catalog=QLHSCDV;Integrated Security=True");
            conn.Open();
        }

        public static void disconnect()
        {
            conn.Close();
        }

        public DataSet FillDataSet(string sql)
        {
            DataSet dataset = new DataSet();
            SqlDataAdapter DataAdap = new SqlDataAdapter(sql, conn);
            DataAdap.Fill(dataset);
            DataAdap.Dispose();
            return dataset;
        }

        public void command(string sql)
        {
            SqlCommand sqlcom = new SqlCommand();
            sqlcom.CommandText = sql;
            sqlcom.Connection = conn;
            sqlcom.ExecuteNonQuery();
        }

        public SqlDataReader ThucHienReader(string sql)
        {
            SqlCommand cmd = new SqlCommand();
            SqlDataReader reader;
            cmd.Connection = conn;
            cmd.CommandText = sql;
            reader = cmd.ExecuteReader();
            return reader;
        }
    }
}
